<!-- 单行文本设置组件 -->
<template>
    <div class="setting_config">
        <div class="label_title">
            <Icon type="md-create" size="18" color="#1055FF" />
            <div class="title">单行文本</div>
        </div>
        <div class="base_config">
            <div class="title">基本设置</div>
            <div class="config_item">
                <div class="label">字段名</div>
                <div class="input">
                    <Input v-model="dynamicForm.formList[dynamicForm.currentIndex].key" clearable />
                </div>
            </div>
            <div class="config_item">
                <div class="label">输入框提示语</div>
                <div class="input">
                    <Input v-model="dynamicForm.formList[dynamicForm.currentIndex].config.placeholder" clearable />
                </div>
            </div>
        </div>
        <div class="show_config" v-if="isShowSetConfig">
            <div class="title">显示逻辑设置</div>
            <div class="input show_set_box">
                <div class="left">已设置{{ dynamicForm.formList[dynamicForm.currentIndex].config.showConfig.length }}条</div>
                <Button type="primary" @click="openShowSetConfig">设置</Button>
            </div>
        </div>
        <div class="rules_config">
            <div class="title">验证设置</div>
            <div class="config_item">
                <div class="label">是否必填</div>
                <div class="input">
                    <Switch v-model="dynamicForm.formList[dynamicForm.currentIndex].required" />
                </div>
            </div>
            <div class="config_item" v-if="dynamicForm.formList[dynamicForm.currentIndex].required">
                <div class="label">为空时错误提示</div>
                <div class="input">
                    <Input v-model="dynamicForm.formList[dynamicForm.currentIndex].rules[0].message" clearable />
                </div>
            </div>
            <div class="config_item" v-if="dynamicForm.formList[dynamicForm.currentIndex].required">
                <div class="label">正则表达式</div>
                <div class="input">
                    <Input v-model="dynamicForm.formList[dynamicForm.currentIndex].rules[1].patten" clearable />
                </div>
            </div>
            <div class="config_item" v-if="dynamicForm.formList[dynamicForm.currentIndex].required">
                <div class="label">正则错误提示</div>
                <div class="input">
                    <Input v-model="dynamicForm.formList[dynamicForm.currentIndex].rules[1].message" clearable />
                </div>
            </div>
        </div>
    </div>
    <showConfig v-if="true" @cancel="closeSetConfig" />
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { dynamicFormStore } from '@/store/dynamicForm';
import showConfig from './showConfig.vue';

const dynamicForm = dynamicFormStore();

// 是否展示显示逻辑设置
const isShowSetConfig = ref(false);

// 是否展示逻辑弹框
const showConfigDrawer = ref(false);

// 打开显示逻辑设置
const openShowSetConfig = () => {
    showConfigDrawer.value = true;
}

// 关闭显示逻辑设置
const closeSetConfig = () => {
    showConfigDrawer.value = false;
}

onMounted(() => {
    dynamicForm.formList.forEach((item, index) => {
        if (item.type == 'switch' || item.type == 'select') {
            // 如自定义组件列表中有，开关或下拉选择
            isShowSetConfig.value = true;
        }
    });
});

</script>

<style scoped lang="scss">
.setting_config {
    .label_title {
        display: flex;
        align-items: center;
        padding-bottom: 10px;
        border-bottom: 1px solid #f1f1f1;

        .title {
            margin-left: 5px;
            font-weight: bold;
        }
    }

    .base_config {
        border-bottom: 1px solid #f1f1f1;
        padding-bottom: 10px;

        .title {
            padding: 10px 0;
            font-weight: bold;
        }

        .config_item {
            margin-bottom: 10px;

            .label {
                padding-bottom: 10px;
            }
        }
    }

    .show_config {
        border-bottom: 1px solid #f1f1f1;
        padding-bottom: 10px;

        .title {
            padding: 10px 0;
            font-weight: bold;
        }

        .show_set_box {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
    }

    .rules_config {
        .title {
            padding: 10px 0;
            font-weight: bold;
        }

        .config_item {
            margin-bottom: 10px;

            .label {
                padding-bottom: 10px;
            }
        }
    }
}
</style>